"""
    字典dict
"""

# 定义字典（映射）

my_dict_1 = {"张三":100, "周杰伦":88, "渣渣灰" :250}
print(my_dict_1)

# 空字典定义
my_dict_2 = {} 
my_dict_3 = dict()

# Key 关键字不允许重复
my_dict_4 = {"张三":100, "张三":88, "渣渣灰" :250}
print(my_dict_4)

# 通过Key取得Value 使用[]
print(my_dict_1["张三"]) # ide 应该可以提示键值

# 字典可以嵌套，但字典的Key不可以为字典
grade_table = {
    "王力鸿" : {"语文": 77, "数学": 66, "英语": 33},
    "周杰伦" : {"语文": 88, "数学": 86, "英语": 55},
    "林俊杰" : {"语文": 99, "数学": 96, "英语": 88}
    }
print(grade_table)
print(grade_table["林俊杰"])
print(grade_table["周杰伦"]["语文"])# 嵌套的话 ide 无法提示多层的键值


# 更新元素，若原本Key不存在则新增元素
my_dict_1["张学友"] = 998
my_dict_1["周杰伦"] = 666
print(my_dict_1)

# 删除
print(my_dict_1.pop("周杰伦"))
print(my_dict_1)

# 清空
my_dict_4.clear()
print(my_dict_4)

# 获取全部关键值
print(my_dict_1.keys())

# 遍历
for key_t in my_dict_1:
    print(key_t, my_dict_1[key_t])
keys_t = my_dict_1.keys()
for key_t in keys_t:
    print(key_t, my_dict_1[key_t])

# 键值对数量
print(len(my_dict_1))